package com.swf.seed.test.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class TaskTimeOut {
	public static void main(String[] args) {
		ExecutorService executor = Executors.newSingleThreadExecutor();
		FutureTask<String> futureTask = new FutureTask<String>(new Callable<String>() {

			public String call() throws Exception {
				TimeUnit.SECONDS.sleep(20);
				return "call";
			}
		});
		executor.execute(futureTask);
		System.out.println("start");
		try {
			executor.awaitTermination(1, TimeUnit.SECONDS);
			System.out.println(futureTask.get());
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			executor.shutdown();
		}
		System.out.println("end");
	}
}
